package com.mydemo.likedy.authority;

import com.mydemo.likedy.Utils.JwtUtils;
import com.mydemo.likedy.properties.UserJwtProperties;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component(value = "postMappingAuthorityVerify")
public class UnifyAuthorityVerify extends DefaultAuthorityVerify{
    @Autowired
    UserJwtProperties userJwtProperties;
    @Override
    public Boolean authorityVerify(HttpServletRequest request, String... permissions) {

        Long uId = JwtUtils.getUserId(request,userJwtProperties.getUserSecretKey(),userJwtProperties.getUserTokenName());
        for (String permission : permissions) {
            if (!AuthorityUtils.verify(uId,permission)) {
                return false;
            }
        }
        return true;
    }
}
